#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i)
    {
        int x;
        cin >> x;
        for (int i = 2; i <= x / i; ++i)
        {
            if (x % i == 0)
            {
                int k = 0;
                while (x % i == 0)
                    ++k, x /= i;
                cout << i << ' ' << k << endl;
            }
        }
        if (x != 1)
            cout << x << ' ' << 1 << endl;
        cout << endl;
    }
    return 0;
}